import { http } from '@/utils'

import type { ResType } from './shared'

// 1.Product 分类接口
export type category = {
  id?: number
  sequence?: number
  title?: string
  router?: string
  description?: string
  image?: string
  alt?: string
  }
export type categoryType = category[]

export type ProductItem = {
    id: number
    title: string
    router: number
    description: string
    default_image: string
    category: category[]
  }

  type ProductRes = ProductItem[]

  export function fetchProductAPI() {
    return http.request<ResType<ProductRes>>({
      url: '/product/category/',
    })
  }


  // 2.ProductNav 分类接口
  export type ReqParams = {
    id: string | undefined
  }

  export function fetchProductCateAPI(params: ReqParams) {
    return http.request<ResType<ProductRes>>({
      url: '/product/category/',
      params,
    })
  }
  

// 3.列表接口
// export type ProductDetail = {
//   id: number
//   title: string
//   router: number
//   description: string
//   default_image: string
//   alt: string
//   keywords: string
//   abstracts: string
//   tag: string
// }

// type ProductList = ProductDetail[]




export interface Response {
  category: Category[];
  code: number;
  data: Datum[];
  [property: string]: any;
}

export interface Category {
  alt?: string;
  banner?: string;
  category?: number;
  category_name?: string;
  default_image?: string;
  description?: string;
  id?: number;
  keywords?: null;
  line_image?: string;
  router?: string;
  title?: string;
  [property: string]: any;
}

export interface Datum {
  abstracts: string;
  alt: string;
  default_image: string;
  description: string;
  id: number;
  keywords: string;
  router: string;
  tag: null | string;
  title: string;
  [property: string]: any;
}

export function fetchProductListAPI(params: ReqParams) {
  return http.request<Response>({
    url: '/product/list/',
    params,
  })
}